package geektime.spring.springbucks.service.impl;

import geektime.spring.springbucks.entity.TOrderCoffee;
import geektime.spring.springbucks.dao.TOrderCoffeeDao;
import geektime.spring.springbucks.service.TOrderCoffeeService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (TOrderCoffee)表服务实现类
 *
 * @since 2022-10-30 00:17:43
 */
@Service("tOrderCoffeeService")
public class TOrderCoffeeServiceImpl implements TOrderCoffeeService {
    @Resource
    private TOrderCoffeeDao tOrderCoffeeDao;

    /**
     * 通过ID查询单条数据
     *
     * @return 实例对象
     */
    @Override
    public TOrderCoffee queryById() {
        return this.tOrderCoffeeDao.queryById();
    }

    /**
     * 分页查询
     *
     * @param tOrderCoffee 筛选条件
     * @param pageRequest  分页对象
     * @return 查询结果
     */
    @Override
    public Page<TOrderCoffee> queryByPage(TOrderCoffee tOrderCoffee, PageRequest pageRequest) {
        long total = this.tOrderCoffeeDao.count(tOrderCoffee);
        return new PageImpl<>(this.tOrderCoffeeDao.queryAllByLimit(tOrderCoffee, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param tOrderCoffee 实例对象
     * @return 实例对象
     */
    @Override
    public TOrderCoffee insert(TOrderCoffee tOrderCoffee) {
        this.tOrderCoffeeDao.insert(tOrderCoffee);
        return tOrderCoffee;
    }

    /**
     * 修改数据
     *
     * @param tOrderCoffee 实例对象
     * @return 实例对象
     */
    @Override
    public TOrderCoffee update(TOrderCoffee tOrderCoffee) {
        this.tOrderCoffeeDao.update(tOrderCoffee);
        return this.queryById();
    }

    /**
     * 通过主键删除数据
     *
     * @return 是否成功
     */
    @Override
    public boolean deleteById() {
        return this.tOrderCoffeeDao.deleteById() > 0;
    }
}
